package com.kuang.controller;

import com.kuang.pojo.AstControllerPoweron;
import com.kuang.service.asset.AstControllerPoweronService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
public class AstControllerPoweronController {

    @Resource
    AstControllerPoweronService astControllerPoweronService;

    /**
     * 获取设备端开机 全部数据
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerPowerons")
    public String getAstControllerPowerons(Model model) {
        List<AstControllerPoweron> astControllerPowerons = astControllerPoweronService.selectAll();
        model.addAttribute("datas", astControllerPowerons);
        model.addAttribute("device_code", "");
        model.addAttribute("ver", "");
        return "mqtt/ast_controller_poweron_list";
    }

    /**
     * 获取设备端开机 全部数据 通过条件
     *
     * @param model
     * @return
     */
    @PostMapping("getAstControllerPoweronsByExample")
    public String getAstControllerHeartsByExample(AstControllerPoweron astControllerPoweron, Model model) {
        List<AstControllerPoweron> astControllerPowerons = astControllerPoweronService.selectAllByExample(astControllerPoweron);
        model.addAttribute("datas", astControllerPowerons);
        model.addAttribute("device_code", astControllerPoweron.getDevice_code());
        model.addAttribute("ver", astControllerPoweron.getVer());
        return "mqtt/ast_controller_poweron_list";
    }

    /**
     * 获取设备信息通过id
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerPoweronById/{id}")
    public String getAstControllerHeartsById(@PathVariable("id") String id, Model model) {
        AstControllerPoweron astControllerPoweron = new AstControllerPoweron();
        astControllerPoweron.setAst_controller_poweron_id(id);
        List<AstControllerPoweron> astControllerPowerons = astControllerPoweronService.selectAllByExample(astControllerPoweron);
        model.addAttribute("data", astControllerPowerons.get(0));
        return "mqtt/ast_controller_poweron_from";
    }

}
